﻿@{
    Script.Require("JQueryPicasa").AtHead();
    Style.Require("JQueryPicasa");
    Script.Require("prettyPhoto").AtHead();
    Style.Require("prettyPhoto");

    // genrerate a unique id for the tag for reference
    string albumId = DateTime.Now.Ticks.ToString();
}
<article id="@albumId">
</article>

@using(Script.Foot()) {
<script type="text/javascript">
//<![CDATA[
    $(function() {

        var gallery = $("#@albumId");

        var userID = '@Model.UserID';
        var albumID = '@Model.AlbumID';
        var authKey = '@Model.AuthKey';

        // adds an unordered list of the gallery images, ready for prettyPhoto
        gallery.picasaGallery(userID, albumID, authKey, function (images) {

            var animation, picasaAlbum;
            picasaAlbum = "<ul class='picasa-album'>\n";
            $.each(images, function(i, element) {
                picasaAlbum += "  <li class='picasa-image'>\n";
                picasaAlbum += "    <a class='picasa-image-large' rel='prettyPhoto[picasa]' href='" + element.url + "'>\n";
                picasaAlbum += "      <img class='picasa-image-thumb' src='" + element.thumbs[0].url + "'/>\n";
                picasaAlbum += "    </a>\n";
                return picasaAlbum += "  </li>\n";
                                    });
            picasaAlbum += "</ul>";
            gallery.append(picasaAlbum);
            animation = function() {
                $(".picasa-image").each(function(index, element) {
                        return $(element).css("visibility", "visible").css("opacity", 0).delay(50 * index).animate({
                            opacity: 1}, 300);
                        });
                    return $(".picasa-album a", gallery).prettyPhoto({
                        slideshow: 5000,
                        autoplay_slideshow: false,
                        social_tools: ''
                    });
            };
            return setTimeout(animation, 300);
        });

    });
//]]>
</script>
}
